package com.ease.framework.layers {
   import com.ease.framework.figures.IFigure;
   import com.ease.framework.gef4p.figures.ILabelFigure;
   import com.ease.framework.gef4p.figures.impl.AnnotationLabelFigure;
   import com.ease.framework.gef4p.figures.impl.AnnotationLabelFigureEditor;
   import com.ease.framework.gef4p.figures.impl.LabelFigureEditor;

   import flash.geom.Point;

   /**
    * 这个层是为了放置Label的编辑对象的.
    *
    * 当Graphical ViewerControl在检测到对ILabelFigure双击或属性编辑操作的时候，
    * 就会在此层创建就会创建一个LabelEditor对象，执行对label的操作.
    *
    */
   public class LabelLayer extends Layer {
      private var labelFE:LabelFigureEditor;
      private var annotationLabelFE:AnnotationLabelFigureEditor;

      public function LabelLayer() {
         super();
         labelFE = new LabelFigureEditor();
         annotationLabelFE = new AnnotationLabelFigureEditor();
         addChild(labelFE);
         addChild(annotationLabelFE);
         labelFE.visible = false;
         annotationLabelFE.visible = false;
      }

      public function editText(labelFigure:IFigure):void {

         var gPoint:Point = labelFigure.localToGlobal(new Point(0, 0));
         var lPoint:Point = this.globalToLocal(gPoint);

         if (labelFigure is AnnotationLabelFigure) {
            annotationLabelFE.setLabelFigure(lPoint, ILabelFigure(labelFigure));

            annotationLabelFE.beginEditText();
         }
         else {

            labelFE.setLabelFigure(lPoint, ILabelFigure(labelFigure));

            labelFE.beginEditText();
         }
      }

      public function get labelFigureEditor():LabelFigureEditor {
         return labelFE;
      }

      public function get annotationLabelFigureE():AnnotationLabelFigureEditor {
         return annotationLabelFE;
      }

   }
}